package com.traw.hat.jdk.collection.map;

import java.util.Objects;

/**
 * @company: 妈妈好网络科技
 * @author: binbin@mamahao.com
 * @date: 2020/3/13
 * @time: 11:57 AM
 * @describe
 */
public class CHashMap<K,V> {


    private static final int DEFAULT_CAPACITY = 16;

    private static final double DEFAULT_LOADFACTOR = 0.75;

    /*容器*/
    transient CNode[] table;
    /*允许的最大容量*/
    transient volatile int capacity;
    /*当前数据量*/
    private volatile int size;
    /*加载因子*/
    private volatile double loadFactory;


    /**
     * default construct
     */
    public CHashMap() {
        this.capacity = DEFAULT_CAPACITY;
        this.loadFactory = DEFAULT_LOADFACTOR;
        table = new CNode[this.capacity];
    }


    /**
     * 1.k 为null 的时候放在首位,只能有数据为null
     * @param k 存放的KEY
     * @param v 存放的Value
     */
    public void put(K k ,V v) {
        //判断是不是为null
        if (Objects.isNull(k)) {
             table [0] = newNode(k,v);
             return;
        }
        int hashCode = k.hashCode();

    }


    private CNode newNode(K k , V v){
        CNode CNode = new CNode();
        CNode.setK(k);
        CNode.setV(v);
        CNode.setPre(null);
        CNode.setNext(null);
        return CNode;
    }


    /**
     * @param <K>
     * @param <V>
     */
    private static class CNode<K,V> {
        private K k;
        private V v;
        private CNode next;
        private CNode pre;

        public K getK() {
            return k;
        }

        public void setK(K k) {
            this.k = k;
        }

        public V getV() {
            return v;
        }

        public void setV(V v) {
            this.v = v;
        }

        public CNode getNext() {
            return next;
        }

        public void setNext(CNode next) {
            this.next = next;
        }

        public CNode getPre() {
            return pre;
        }

        public void setPre(CNode pre) {
            this.pre = pre;
        }
    }

}
